package com.练习案例.五个人抢三个红包;

import java.util.Random;

public class MyThread extends Thread{//五个人抽三个红包，红包一共一百
    static double money=100;
    static double count=3;
    static final double MIN=0.01;

    @Override
    public void run() {

        synchronized (MyThread.class){
            double prize=0;
            if(count==0){//红包个数为0时候,不用抽了
                    System.out.println(getName()+"没有抽到");
            }else {
                if(count==1){
                    //红包个数唯一，所有钱到这个给红包给出去就行
                    prize=money;
                }else {
                    //不是就随机抽取，0.01到99.8
                    Random random=new Random();
                    Double bound=money-(count-1)*0.01;
                    prize=random.nextDouble(bound);//0-99.98
                    if(prize<MIN){//钱比最小值少
                        prize=MIN;
                    }
                }
                money=money-prize;
                count--;
                System.out.println(getName()+"抢到了"+money);
            }
        }
    }

}
